﻿
function $import(path, type) {
    var i,
      base,
      src = "globle.js",
      scripts = document.getElementsByTagName("script");

    for (i = 0; i < scripts.length; i++) {
        if (scripts[i].src.match(src)) {
            base = scripts[i].src.replace(src, "");
            break;
        }
    }

    if (type == "css") {
        document.write("<" + "link href=\"" + base + path + "\" rel=\"stylesheet\" type=\"text/css\"></" + "link>");
    } else {
        document.write("<" + "script src=\"" + base + path + "\"></" + "script>");
    }
}

//Sample: String.format("I am {0}, you are {1}","a","b");
String.format = function() {
    if (arguments.length == 0)
        return null;

    var str = arguments[0];
    for (var i = 1; i < arguments.length; i++) {
        var re = new RegExp('\\{' + (i - 1) + '\\}', 'gm');
        str = str.replace(re, arguments[i]);
    }
    return str;
}

//string To Date
String.toDate = function(fmt, str) {
    var patten = /(y|M|d|h|m|s)/g;
    var result = { y: 0, M: 0, d: 0, h: 0, m: 0, s: 0 };
    var r = patten.exec(fmt);
    var currentChar = r[0];
    while (r != null) {
        var a = str.substr(r.index, 1);
        if (currentChar != r[0]) {
            currentChar = r[0];
        }
        result[currentChar] = (result[currentChar] * 10) + parseInt(a);
        r = patten.exec(fmt);
    }
    return new Date(result.y, result.M, result.d, result.h, result.m, result.s);
}

function getAbsPosition(obj) {
    return { left: getAbsoluteLeft(obj), top: getAbsoluteTop(obj) };
}

function getAbsoluteLeft(o) {//html object
    // Get an object left position from the upper left viewport corner    
    oLeft = o.offsetLeft            // Get left position from the parent object
    while (o.offsetParent != null) {   // Parse the parent hierarchy up to the document element
        oParent = o.offsetParent    // Get parent object reference
        oLeft += oParent.offsetLeft // Add parent left position
        o = oParent
    }
    return oLeft
}

function getAbsoluteTop(o) {
    // Get an object top position from the upper left viewport corner    
    oTop = o.offsetTop            // Get top position from the parent object
    while (o.offsetParent != null) { // Parse the parent hierarchy up to the document element
        oParent = o.offsetParent  // Get parent object reference
        oTop += oParent.offsetTop // Add parent top position
        o = oParent
    }
    return oTop
}



$(document).ready(function() {
    iniButtons();
});

// button样色
//--------------------------------------------
function iniButtons() {
    $("input[type='button'],input[type='submit'],button").addClass("ui-corner-all ui-state-hover").hover(
    function() { $(this).removeClass("ui-state-default").addClass("ui-state-active"); },
    function() { $(this).addClass("ui-state-default").removeClass("ui-state-active"); }
    );
}

            




    